﻿using FI.Core.Utilities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace FI.Core
{
    /// <summary>
    /// This class defines a pageable data collection.
    /// </summary>
    /// <typeparam name="T"></typeparam>
    [DataContract(Namespace = Constants.Namespace, Name = "PageableResultOf{0}")]
    public class PageableResult<T>
    {
        /// <summary>
        /// Gets or sets the data items.
        /// </summary>
        /// <value>The data items.</value>
        [DataMember]
        public T[] Items { get; set; }

        /// <summary>
        /// Gets or sets the count of data items in all pages.
        /// </summary>
        /// <value>The count of data items in all pages.</value>
        [DataMember]
        public int TotalRecords { get; set; }

        /// <summary>
        /// Gets or sets <seealso cref="Uri"/> linking to the next page.
        /// </summary>
        /// <value>The <seealso cref="Uri"/> linking to the next page.</value>
        [DataMember]
        public Uri NextPage { get; set; }

        /// <summary>
        /// Initializes a new instance of the <see cref="PageableResult{T}"/> class.
        /// </summary>
        /// <param name="items">The data items.</param>
        /// <param name="totalRecords">The count of data items in all pages.</param>
        /// <param name="nextPage">The <seealso cref="Uri"/> linking to the next page.</param>
        public PageableResult(IEnumerable<T> items, int totalRecords, Uri nextPage = null)
        {
            Guard.ArgumentNotNull(items, "items");

            this.Items = items.ToArray();
            this.TotalRecords = totalRecords;
            this.NextPage = nextPage;
        }
    }
}